﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;

using Revis.VClinicNet.Core.Domain.Persistence;

namespace Revis.VClinicNet.Core.Domain.Persistence.Nh.Tests.Db
{
    public class SqlLiteTestDatabase : AbstractDatabase
    {
        public override void Configure()
        {
            _configuration = Fluently.Configure()
                                .Database(() => {
                                    return SQLiteConfiguration.Standard
                                        .InMemory()
                                        .ShowSql()
                                        .CurrentSessionContext("thread_static");
                                })
                                .Mappings(m => {
                                    m.HbmMappings.AddFromAssembly(
                                        Assembly.LoadFrom("Revis.VClinicNet.Core.Domain.Persistence.Nh.dll"));
                                })
                                .BuildConfiguration();
            _factory = _configuration.BuildSessionFactory();
        }

        public override void ExportSchema()
        {
            ISession session = _factory.GetCurrentSession();
            new SchemaExport(_configuration).Execute(false, true, false, session.Connection, null);
        }
    }
}
